package com.woniu.finance.service.impl;


import com.woniu.finance.entity.RoleMenu;
import com.woniu.finance.mapper.RoleMenuMapper;
import com.woniu.finance.service.IRoleMenuService;
import com.woniu.util.utils.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色菜单表 服务实现类
 * </p>
 *
 * @author o
 * @since 2023-04-25
 */
@Service
public class RoleMenuServiceImpl implements IRoleMenuService {

    @Autowired(required = false)
    private RoleMenuMapper roleMenuMapper;

    @Override
    public HttpResult<?> saveRoleMenu(RoleMenu roleMenu) {
        try {
            roleMenuMapper.insert(roleMenu);
            return new HttpResult<>().ok();
        }catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> removeRoleMenu(Integer id) {
        try {
            roleMenuMapper.deleteById(id);
            return new HttpResult<>().ok();
        }catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> modifyRoleMenu(RoleMenu roleMenu) {
        try {
            roleMenuMapper.updateById(roleMenu);
            return new HttpResult<>().ok();
        }catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> findAllRoleMenu() {
        try {
            List<RoleMenu> roleMenu = roleMenuMapper.selectList(null);
            return new HttpResult().ok(roleMenu);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult().fail();
        }
    }

    @Override
    public HttpResult<?> findRoleMenuById(Integer id) {
        try {
            RoleMenu roleMenu = roleMenuMapper.selectById(id);
            return new HttpResult<>().ok(roleMenu);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }
}
